<?php include _include(APP_PATH.'view/htm/header.inc.htm');?>

<div class="row">
	<div class="col-lg-6 offset-lg-3">
		<div class="card">
			<!--{hook user_create_card_title.htm}-->
			<div class="card-block">
				<h4 class="card-title"><?php echo lang('user_resetpw');?></h4>
				<form action="<?php echo url('user-resetpw');?>" method="post" id="form">
					<p class="input-group">
						<span class="input-group-addon"><i class="icon icon-envelope"></i></span>
						<input type="text" class="form-control" placeholder="<?php echo lang('email');?>" name="email" id="email">
					</p>
					<dl class="row">
						<dt style="width: 68%">
							<p class="input-group">
								<span class="input-group-addon"><i class="icon icon-key"></i></span>
								<input type="text" class="form-control" placeholder="<?php echo lang('verify_code');?>" name="verify_code" id="verify_code">
							</p>
						</dt>
						<dd class="text-right vtop">
							<button type="submit" class="btn btn-primary btn-sm m-l-1" id="send" data-loading-text="<?php echo lang('sending');?>..." action="<?php echo url('user-resetpw_sendcode');?>"><?php echo lang('send_verify_code');?></button>
						</dd>
					</dl>
					<p>
						<button type="submit" class="btn btn-primary btn-block" id="submit" data-loading-text="<?php echo lang('submiting');?>..." <?php if($conf['user_create_email_on']) { ?>disabled<?php } ?>><?php echo lang('next_step');?></button>
					</p>
				</form>
			</div>
		</div>
	</div>
</div>

<?php include _include(APP_PATH.'view/htm/footer.inc.htm');?>

<script>
var jform = $('#form');
var jsubmit = $('#submit');
var jsend = $('#send');
jsend.on('click', function() {
	jform.reset();
	jsend.button('loading');
	var postdata = jform.serialize();
	$.xpost(jsend.attr('action'), postdata, function(code, message) {
		if(code == 0) {
			$.alert(message);
			$('#verify_code').focus();
			var t = 60; // 倒计时
			jsend.button('<?php echo lang('user_send_sucessfully');?> 60 ');
			jsubmit.button('reset');
			// 倒计时，重新发送
			var handler = setInterval(function() {
				jsend.button('<?php echo lang('user_send_sucessfully');?> '+(--t)+' ');
				if(t == 0) {
					clearInterval(handler);
					jsend.button('reset');
				}
			}, 1000);
		} else if(code < 0) {
			$.alert(message);
			jsend.button('reset');
		} else {
			jform.find('[name="'+code+'"]').alert(message).focus();
			jsend.button('reset');
		}
	});
	return false;
});

jform.on('submit', function() {
	jform.reset();
	jsubmit.button('loading');
	var postdata = jform.serialize();
	$.xpost(jform.attr('action'), postdata, function(code, message) {
		if(code == 0) {
			$.alert(message);
			jsubmit.button(message).delay(1000).location(xn.url('user-resetpw_complete'));
		} else if(code < 0) {
			$.alert(message);
			jsubmit.button('reset');
		} else {
			jform.find('[name="'+code+'"]').alert(message).focus();
			jsubmit.button('reset');
		}
	});
	return false;
});

</script>